package ua.tyran53red.banner;

import java.awt.Color;
import java.awt.Image;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class BannerPanel extends JPanel implements Runnable {
	private static final long serialVersionUID = 1L;
	private String iconMas[];
	private int iconWidth[];
	private int iconHeight[];
	                                
	
	public BannerPanel(int width, int height, String icomMas[], int iconWidth[], int iconHeight[]) {
		this.iconMas = icomMas;
		this.iconWidth = iconWidth;
		this.iconHeight = iconHeight;
		setBounds(0, 25, width, height);
		setBackground(new Color(255, 255, 255));
		setLayout(null);
		new Thread(this).start();
	}

	public void run() {
		Random random = null;
		JLabel lblImage = null;
		ImageIcon icon = null;
		ImageIcon image = null;
		int next;
		
		while (true) {
			try {
				this.removeAll();
				random = new Random();
				next = random.nextInt(4);
				image = new ImageIcon("data/images/" + iconMas[next]);
				icon = new ImageIcon(image.getImage().getScaledInstance(iconWidth[next], iconHeight[next], Image.SCALE_DEFAULT));
				lblImage = new JLabel(icon , JLabel.CENTER);
				lblImage.setBounds((this.getWidth() - iconWidth[next])/2, 10, icon.getIconWidth(), icon.getIconHeight());
				this.add(lblImage);
				this.repaint();
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
